<?php require('connections/con_gl.php'); ?>
<?php
cekAkses($_SESSION[akses],"L-4");
$mulai = $_GET[mulai];
$sampai = $_GET[sampai];
$maxRows_data = 8;
$pageNum_data = 0;
if (isset($_GET['pageNum_data'])) {
  $pageNum_data = $_GET['pageNum_data'];
}
$startRow_data = $pageNum_data * $maxRows_data;

mysql_select_db($database_con_gl, $con_gl);
$query_data = "SELECT * FROM gl_rtrans";
if((isset($_GET[tipe_j]) AND $_GET[tipe_j]<>'ALL') OR ($mulai <>'Mulai...' AND $sampai<>'Sampai...')) {
	$query_data .=" where ";
}
if(isset($_GET[tipe_j]) AND $_GET[tipe_j]<>'ALL') {
	$tip = $_GET[tipe_j];
	$query_data .="no_ref LIKE '%%$tip%%'";
}
if((isset($_GET[tipe_j]) AND $_GET[tipe_j]<>'ALL') AND ($mulai <>'Mulai...' AND $sampai<>'Sampai...')) {
	$query_data .=" AND ";
}
if($mulai <>'Mulai...' AND $sampai<>'Sampai...') {
	$query_data .="tgl between '$mulai' AND '$sampai'";
}
if(!strstr($_SESSION[akses],'A-1-4')) {
	if(!strstr($query_data," where ")) {
		$query_data .=" where gudang='$_SESSION[lokasi]'";	
	}else{
		$query_data .=" AND gudang='$_SESSION[lokasi]'";
	}
}
$query_data .=" ORDER BY gl_rtrans.tgl desc";
$data = mysql_query($query_data, $con_gl) or die(mysql_error());
$totalRows_data = mysql_num_rows($data);

$totalPages_data = floor($totalRows_data / $maxRows_data);

$query_data .=" LIMIT $startRow_data, $maxRows_data";
$data = mysql_query($query_data, $con_gl) or die(mysql_error());
$totalRow_data = mysql_num_rows($data);
$row_data = mysql_fetch_assoc($data);

include('include/widget_exportall.php');
?>
<link href="ccss/ui.datepicker.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="js/ui.datepicker.js"></script>
<script type="text/javascript">
<!--
$(function()
      {
        $('.calendar').datepicker({
            appendText : "",
            dateFormat : 'yy/mm/dd'
          });
      });
	  
</script>
<link href="css/print.css" rel="stylesheet" type="text/css" media="print"/>
<h1>Daftar Jurnal <?php if($_GET['mulai']<>'Mulai...' AND isset($_GET['mulai'])) { tanggal($_GET['mulai'],"tampilkan"); } ?> - <?php if($_GET['sampai']<>'Sampai...' AND isset($_GET['sampai'])) { tanggal($_GET['sampai'],"tampilkan"); } ?></h1>
<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0"> 
  <tr valign="top" id="print">
    <td colspan="3" align="right"><form id="search" name="search" method="post" action="">
			<label>
			<select name="tipe_j" id="tipe_j">
			  <option value="ALL" selected="selected">ALL Jurnal</option>
			  <option value="TH">Transaksi Harian</option>
			  <option value="TRF">Transfer</option>
			  <option value="CR">Kas Masuk</option>
			  <option value="BO">Kas Keluar</option>
			  <option value="PYN">Persediaan</option>
			  <option value="PJ">Pembelian</option>
			  <option value="SJ">Penjualan</option>
		    </select>
			</label>
			<label>
			<input name="Mulai" type="text" class="calendar" id="Mulai" value="<?php if(empty($mulai)) echo "Mulai...";else echo $mulai;?>"onblur="if(this.value=='') this.value='Mulai...';" onfocus="if(this.value=='Mulai...') this.value='';"></label>
			s/d
			<label><input name="Sampai" type="text" class="calendar" id="Sampai" value="<?php if(empty($sampai)) echo "Sampai...";else echo $sampai;?>"onblur="if(this.value=='') this.value='Sampai...';" onfocus="if(this.value=='Sampai...') this.value='';"></label>
			<label>
            <input name="Search" type="submit" id="Search" value="Tampilkan" />
            </label>
    </form><?php if(isset($_POST[Search])) { echo "<script>window.location=\"index.php?component=jurnal&tipe_j=".$_POST[tipe_j]."&&mulai=".$_POST[Mulai]."&sampai=".$_POST[Sampai]."\";</script>";} ?></td>
  </tr>
  <?php if($totalRows_data > 0) { ?>
  <?php do { ?>
      <tr valign="top" bgcolor="#007EBF">
        <td width="136" align="center"  style="border-bottom:solid 1px #E2EAC1;border-right:solid 1px #E2EAC1;border-left:solid 1px #E2EAC1;"><strong style="color:#FFFFFF;">Tanggal</strong></td>
        <td width="226" align="center" style="border-bottom:solid 1px #E2EAC1;border-right:solid 1px #E2EAC1;"><strong style="color:#FFFFFF;">No Referensi </strong></td>
        <td width="508" style="border-bottom:solid 1px #E2EAC1;border-right:solid 1px #E2EAC1;"><strong style="color:#FFFFFF;">Keterangan</strong></td>
      </tr>
    <tr valign="top" bgcolor="#FFFFFF">
      <td align="center"  style="border-bottom:solid 1px #E2EAC1;border-right:solid 1px #E2EAC1;border-lefts:solid 1px #E2EAC1;">
        &nbsp;<?php tanggal($row_data['tgl'],"tampilkan"); ?></td>
      <td align="center" style="border-bottom:solid 1px #E2EAC1;border-right:solid 1px #E2EAC1;"><?php echo $row_data[no_ref];?>&nbsp;</td>
      <td style="border-bottom:solid 1px #E2EAC1;border-rights:solid 1px #E2EAC1;"><?php echo $row_data[keterangan];?>&nbsp;</td>
    </tr>
	<?php 
	mysql_select_db($database_con_gl, $con_gl);
$query_trans = "SELECT gl_trans.transaksi, gl_trans.id, gl_trans.total, gl_trans.pos, gl_trans.akun as coa, gl_akun.akun as namakun FROM gl_trans, gl_akun WHERE gl_akun.id = gl_trans.akun AND gl_trans.no_ref='$row_data[no_ref]' ORDER BY gl_trans.pos asc";
$trans = mysql_query($query_trans, $con_gl) or die(mysql_error());
$row_trans = mysql_fetch_assoc($trans);
$totalRows_trans = mysql_num_rows($trans);
	?>
	<tr valign="top" bgcolor="#FFFFFF">
        <td colspan="3"><table width="98%" border="0" align="right" cellpadding="3" cellspacing="0" class="datatable">
            <tr>
              <th><strong>Transaksi </strong></th>
              <th width="25%" align="center" valign="top"><strong>Akun</strong></th>
              <th width="15%" align="center" valign="top"><strong>Debet</strong></th>
              <th width="15%" align="center" valign="top"><strong>Kredit</strong></th>
            </tr>
            <?php $totdeb=0; $totkre=0; if($totalRows_trans > 0)  { ?>
            <?php  do { ?>
            <tr valign="top" bgcolor="#FFFFFF">
              <td><?php echo $row_trans['transaksi']; ?></td>
              <td align="center" valign="top"><?php echo $row_trans['coa']; ?> - <?php echo $row_trans['namakun']; ?></td>
              <td align="right" valign="top"><?php if($row_trans['pos']=='D') { $totdeb += $row_trans['total']; echo number_format($row_trans['total'],0,',','.').",-";}else{ echo "0,00";} ?></td>
              <td align="right" valign="top"><?php if($row_trans['pos']=='K') { $totkre += $row_trans['total']; echo number_format($row_trans['total'],0,',','.').",-";}else{ echo "0,00";} ?></td>
            </tr>
            <?php } while ($row_trans = mysql_fetch_assoc($trans)); ?>
            <?php } ?>
            <tr valign="top">
              <td colspan="2" align="right"><strong>Total : </strong></td>
              <td align="right" valign="top" bgcolor="#EEEEEE"><strong><?php echo number_format($totdeb,0,',','.').",-";?></strong></td>
              <td align="right" valign="top" bgcolor="#EEEEEE"><strong><?php echo number_format($totkre,0,',','.').",-";?></strong></td>
            </tr>
          </table></td>
	</tr>
      <?php } while ($row_data = mysql_fetch_assoc($data)); ?>
  <tr id="print">
    <td colspan="3"><table border="0" align="left">
      <tr>
        <td width="23%" align="center"><?php if ($pageNum_data > 0) { // Show if not first page ?>
            <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, 0, $queryString_data); ?>"><img src="First.gif" border="0" /></a>
            <?php } // Show if not first page ?>
        </td>
        <td width="31%" align="center"><?php if ($pageNum_data > 0) { // Show if not first page ?>
            <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, max(0, $pageNum_data - 1), $queryString_data); ?>"><img src="Previous.gif" border="0" /></a>
            <?php } // Show if not first page ?>
        </td>
        <td width="23%" align="center"><?php if ($pageNum_data < $totalPages_data) { // Show if not last page ?>
            <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, min($totalPages_data, $pageNum_data + 1), $queryString_data); ?>"><img src="Next.gif" border="0" /></a>
            <?php } // Show if not last page ?>
        </td>
        <td width="23%" align="center"><?php if ($pageNum_data < $totalPages_data) { // Show if not last page ?>
            <a href="<?php printf("%s?pageNum_data=%d%s", $currentPage, $totalPages_data, $queryString_data); ?>"><img src="Last.gif" border="0" /></a>
            <?php } // Show if not last page ?>
        </td>
      </tr>
    </table></td>
  </tr>
   <?php }else if($mulai<>'' AND $sampai<>'' AND $totalRows_data ==0) { ?>
  <tr>
      <td colspan="3">Data tidak ada !!!</td>
  </tr>
  <?php } ?>
</table>
<?php
//mysql_free_result($data);

//mysql_free_result($trans);

//mysql_free_result($period);
?>
